package com.neu.demo;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;

public class Demo02 {
	public static  	ArrayList<String> al = new ArrayList<>();
	public static   HashSet<User> hs = new HashSet<>();
	@SuppressWarnings("rawtypes")
	public static   HashSet hs1 = new HashSet();
	 /**
	    * 
	    * @param args
	    * 对集合al与hs进行元素添加，注意观察泛型的作用
	    */
		@SuppressWarnings("unchecked")
		public static void add() {
			al.add("aaa");
			al.add("123");
			hs.add(new User("user_001", "tom"));
			hs.add(new User("user_002", "jerry"));
			hs1.add("abc");
			hs1.add(new User("user_003","rose"));
		}
		
		
			/**
			 * 
			 * @param args
			 * 对 al   hs   hs1   进行遍历
			 */
	
	//  ArrayList<String> al = new ArrayList<>();
    //  给定的数据类型为 String  
	@SuppressWarnings({ "unused", "rawtypes" })
	public static void iterator() {
		Iterator<String> ite_al = al.iterator();
		while(ite_al.hasNext()) {
			String a = ite_al.next();
			System.out.println("al中的元素有:"+a);
		}
		
	//    HashSet<User> hs = new HashSet<>();  
	//     给定的数据类型为 User  
		Iterator<User> ite_hs = hs.iterator();
		while (ite_hs.hasNext()) {
			User uesr = ite_hs.next();
			System.out.println("员工的信息:"+uesr);
			
		}
		//public static   HashSet hs1 = new HashSet();
		//  没有给定数据类型   默认Objeck  
		
		Iterator ite_hs1 = hs1.iterator();
		Object obj = null;
		User user = null;
		while(ite_hs1.hasNext()) {
			obj = ite_hs1.next();
			if(obj instanceof User) {
				 user = (User)obj;
				 System.out.println(hs1);
				 System.out.println(user.getName());
			}
		}
//		while(ite_hs1.hasNext()) {
//			if(ite_hs1.next() instanceof User) {
//				User uesr = (User)ite_hs1.next();
//				System.out.println(uesr.getId());
//			}
//		}
	}
	public static void main(String[] args) {
		add();
		iterator();
	}
}
